import 'package:flutter/material.dart';

class ValCommonText extends StatelessWidget {
  final String text;
  final double fontSize;
  final Color fontColor;
  final int? maxLines;
  final TextOverflow? overflow;
  final FontWeight? fontWeight;
  final TextAlign? textAlign;
  final FontStyle fontStyle;
  final double? leading;
  final double? letterSpacing;
  final TextDecoration? decoration;
  final double? height;
  final bool forceStrutHeight;

  @override
  Widget build(BuildContext context) {
    double textScale = MediaQuery.of(context).textScaleFactor;
    double tempLeading = leading ?? 0;
    if (leading != null && leading! > 0) {
      if (textScale > (leading! + 1)) {
        //字体过大，简介暂时定为0
        tempLeading = 0;
      } else if (textScale > 1) {
        tempLeading = leading! + 1 - textScale;
      }
    }
    return Text(text,
        style: TextStyle(
          fontSize: fontSize,
          color: fontColor,
          fontStyle:  fontStyle,
          fontWeight: fontWeight,
          letterSpacing: letterSpacing,
          decoration: decoration,
        ),
        maxLines: maxLines,
        overflow: overflow,
        strutStyle: StrutStyle(
          leading: tempLeading,
          height: height,
          fontWeight: fontWeight,
          fontSize: fontSize,
          forceStrutHeight: forceStrutHeight,
        ),
        textAlign: textAlign);
  }

  ///单行粗体
  const ValCommonText.oneLineBold(
      this.text,
      this.fontSize,
      this.fontColor, {
        super.key,
        this.maxLines = 1,
        this.overflow = TextOverflow.ellipsis,
        this.fontWeight = FontWeight.w600,
        this.textAlign,
        this.fontStyle = FontStyle.normal,
        this.leading = 0.1,
        this.letterSpacing,
        this.decoration,
        this.height = 1.1,
        this.forceStrutHeight = true,
      });

  ///单行
  const ValCommonText.oneLine(
      this.text,
      this.fontSize,
      this.fontColor, {
        super.key,
        this.maxLines = 1,
        this.overflow = TextOverflow.ellipsis,
        this.fontWeight,
        this.fontStyle = FontStyle.normal,
        this.textAlign,
        this.leading = 0.1,
        this.letterSpacing,
        this.decoration,
        this.height = 1.1,
        this.forceStrutHeight = true,
      });

  ///没有行数限制
  const ValCommonText.moreLine(
      this.text,
      this.fontSize,
      this.fontColor, {
        super.key,
        this.maxLines,
        this.overflow,
        this.fontWeight,
        this.fontStyle = FontStyle.normal,
        this.textAlign,
        this.leading = 0.5,
        this.letterSpacing,
        this.decoration,
        this.height = 1,
        this.forceStrutHeight = true,
      });

}
